home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / Development Tools & Languages / AppsToGo / DTS.Lib / DTS.Lib.headers / TextEditControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  38.2 KB  |  951 lines  |  [TEXT/KAHL]

  1. #ifndef __TEXTEDITCONTROL__
  2. #define __TEXTEDITCONTROL__
  3.  
  4. #ifndef __TYPES__
  5. #include <Types.h>
  6. #endif
  7.  
  8. #ifndef __TEXTEDIT__
  9. #include <TextEdit.h>
  10. #endif
  11.  
  12. #ifndef __TEXTSERVICES__
  13. #include <TextServices.h>    
  14. #endif
  15.  
  16. #ifndef    __TSMTE__
  17. #include "TSMTE.h"
  18. #endif
  19.  
  20. #ifndef __WINDOWS__
  21. #include <Windows.h>
  22. #endif
  23.  
  24. typedef Boolean    (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, short *handled);
  25.     /*
  26.     **    ¶ Prototype for TextEditControl key filter function.
  27.     **
  28.     **    INPUT:    teHndl        TextEdit record that filter relates to.
  29.     **            event        Pointer to event record holding key event.
  30.     **    OUTPUT:    handled        Pointer to short to hold action.
  31.     **    RESULT:    Boolean        Return true if key should be filtered.
  32.     **
  33.     **    Each TextEdit control can have its own separate filter proc.  Just call
  34.     **    CTESetKeyFilter, and pass in the procPtr of your filter.  If the character
  35.     **    should be filtered, the filter should return true.  If you do return true,
  36.     **    then the value of “handled” is returned bt CTEKey.
  37.     **
  38.     **    Note that “handled” is initialized to 0, so you don’t have to set it unless
  39.     **    the desired  return value is other than 0.
  40.     **
  41.     **    __________
  42.     **
  43.     **    Also see:    CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */ 
  44.  
  45. typedef Boolean    (*CTEFastKeysProcPtr)(TEHandle teHndl, EventRecord *event);
  46.     /*
  47.     **    ¶ Prototype for TextEditControl fast keys function.
  48.     **
  49.     **    INPUT:    teHndl        TextEdit record that fast keys proc relates to.
  50.     **            event        Pointer to event record holding key event.
  51.     **    RESULT:    Boolean        Return true if key should be seen by application.
  52.     **
  53.     **    On slower Macs, going back to the main event loop for every character can
  54.     **    adversely affect performance for TextEdit (and therefore the TextEdit control).
  55.     **    By using a fast-keys filter, you can prevent looping back to the main event loop.
  56.     **    The TextEdit control will loop itself, as long as there is a key in the
  57.     **    event queue.  Not all keys should be processed in fast-keys mode.  That is
  58.     **    the purpose of the filter.  If the filter determines that the key is okay to
  59.     **    be handled fast, it returns true.  If the key should be handled by the
  60.     **    application return false.
  61.     **
  62.     **    __________
  63.     **
  64.     **    Also see:    CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */
  65.  
  66. typedef struct CTEDataRec {
  67.     short                maxTextLen;
  68.     Boolean                newUndo;
  69.     short                undoSelStart;
  70.     short                undoSelEnd;
  71.     Handle                undoText;
  72.     StScrpHandle        undoStyl;
  73.     short                mode;
  74.     Rect                brdrRect;
  75.     CTEKeyFilterProcPtr    keyFilter;
  76.     CTEFastKeysProcPtr    fastKeys;
  77.     TSMDocumentID        docID;
  78. } CTEDataRec;
  79. typedef CTEDataRec *CTEDataPtr, **CTEDataHndl;
  80.  
  81.  
  82.  
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86.  
  87.  
  88.  
  89. pascal void        ASMNOCARET(Rect *caretRect);
  90. pascal Boolean    ASMTECLIKLOOP(void);
  91.     /*    Entry-points for the assembly glue. */
  92.  
  93. void            CTEActivate(Boolean active, TEHandle teHndl);
  94.     /*
  95.     **    ¶ Activate the indicated TextEdit record (and deactivate any other active one).
  96.     **
  97.     **    INPUT:    active        True to activate or false to deactivate.
  98.     **            teHndl        TextEdit record to activate (or deactivate).
  99.     **
  100.     **    Activate (or deactivate) this TextEdit record.  If another is currently
  101.     **    active, deactivate that one.  The view control for this TextEdit record is
  102.     **    also flagged to indicate which was the last active one for this window.
  103.     **    If the previous active TextEdit record was in the same window, then flag
  104.     **    the old one off for this window.  The whole point for this per-window
  105.     **    flagging is so that activate events can reactivate the correct TextEdit
  106.     **    control per window.
  107.     **
  108.     **    __________
  109.     **
  110.     **    Also see:    CTEFindActive, CTEWindActivate. */
  111.  
  112. Boolean            CTEClick(WindowPtr window, EventRecord *event, short *action);
  113.     /*
  114.     **    ¶ Handles a mouseDown in the content of a window.
  115.     **
  116.     **    INPUT:    window        Window click was made in.
  117.     **            event        Pointer to event record holding mouseDown event.
  118.     **    OUTPUT:    action        Action taken by the TextEdit control.
  119.     **                        Pass in nil if you don’t care.
  120.     **    RESULT:    Boolean        True if control used the event.
  121.     **
  122.     **    This is called when a mouseDown occurs in the content of a window.  It
  123.     **    returns true if the mouseDown caused a TextEdit action to occur.  Events
  124.     **    that are handled include if the user clicks on a scrollbar that is
  125.     **    associated with a TextEdit control.
  126.     **
  127.     **    if CTEClick returns false, action is 0
  128.     **    if CTEClick returns true,  action is:
  129.     **        -1 if control was activated by clicking on the TextEdit control or related scrollbar.
  130.     **         0 if control that was clicked on was already active.
  131.     **
  132.     **    __________
  133.     **
  134.     **    Also see:    CTEEvent, CTEKey. */
  135.  
  136. void            CTEClikLoop(void);
  137.     /*
  138.     **    ¶ Utility function for TextEdit control.
  139.     **
  140.     **    This is the custom clikLoop, which is called from the assembly glue code.
  141.     **    This handles updating the scrollbars as the user is drag-selecting in
  142.     **    the TextEdit control. */
  143.  
  144. ControlHandle    CTEClipboard(short menuID);
  145.     /*
  146.     **    ¶ Handles cut-copy-paste-clear for the currently active TextEdit control.
  147.     **
  148.     **    INPUT:    menuID            2 (cut), 3 (copy), 4 (paste), 5 (clear).
  149.     **    RESULT:    ControlHandle    Control that took the menu event.
  150.     **
  151.     **    Do the cut-copy-paste-clear operations for the currently active
  152.     **    TextEdit control.  Caller assumes appropriateness of the call.  Typically,
  153.     **    this routine won’t be called at an inappropriate time, since the menu
  154.     **    item should be enabled or disabled correctly.
  155.     **
  156.     **    Use CTEEditMenu to set the menu items undo-cut-copy-paste-clear correctly
  157.     **    for the active TextEdit control.  Since undo isn’t currently supported,
  158.     **    all that CTEEditMenu does for the undo case is to deactivate it right now.
  159.     **    If a TextEdit control content changes due to this operation, the control
  160.     **    handle is returned.
  161.     **
  162.     **    __________
  163.     **
  164.     **    Also see:    CTEConvertClipboard, CTEEditMenu. */
  165.  
  166. void            CTEConvertClipboard(Boolean convertClipboard, Boolean becomingActive);
  167.     /*
  168.     **    ¶ This is an empty function, used for backward-compatibility.
  169.     **
  170.     **    This used to be called to convert the clipboard.  This task is now handled
  171.     **    elsewhere, automatically.  Calls to this function are obsolete, and can be
  172.     **    removed.
  173.     **
  174.     **    __________
  175.     **
  176.     **    Also see:    CTEClipboard, CTEEditMenu. */
  177.  
  178. ControlHandle    CTECtlHit(void);
  179.     /*
  180.     **    ¶ Returns the control that was hit (if any) by FindControl.
  181.     **
  182.     **    RESULT:    ControlHandle    Control that was hit.
  183.     **
  184.     **    The TextEdit control that was hit by calling FindControl is saved in a
  185.     **    global variable, since the CDEF has no way of returning what kind it was.
  186.     **    To determine that it was a TextEdit control that was hit, first call this
  187.     **    function.  The first call returns the old value in the global variable,
  188.     **    plus it resets the global to nil.  Then call FindControl, and then
  189.     **    call this function again.  If it returns nil, then a TextEdit control
  190.     **    wasn’t hit.  If it returns non-nil, then it was a TextEdit control that
  191.     **    was hit, and specifically the one returned. */
  192.  
  193. void            CTEDispose(TEHandle teHndl);
  194.     /*
  195.     **    ¶ Disposes the TERecord, TextEdit control, and any related scrollbars.
  196.     **
  197.     **    INPUT:    teHndl        TextEdit handle (of the TextEdit control) to dispose.
  198.     **
  199.     **    Disposes of the TERecord, TextEdit control, and any related scrollbars.
  200.     **
  201.     **    __________
  202.     **
  203.     **    Also see:    CTEDisposeView. */
  204.  
  205. TEHandle        CTEDisposeView(ControlHandle viewCtl);
  206.     /*
  207.     **    ¶ Dispose the view control and related scrollbars, but not the TERecord.
  208.     **
  209.     **    INPUT:    viewCtl        Control to dispose.
  210.     **    RESULT:    TEHandle    Orphaned TextEdit record.
  211.     **
  212.     **    Dispose of the view control and related scrollbars.  This function also
  213.     **    returns the handle to the TextEdit record, since it was just orphaned.
  214.     **    Use this function if you want to get rid of a TextEdit control, but you
  215.     **    want to keep the TextEdit record.
  216.     **
  217.     **    __________
  218.     **
  219.     **    Also see:    CTEDispose. */
  220.  
  221. short            CTEDocHeight(TEHandle teHndl);
  222.     /*
  223.     **    ¶ Returns the full document height.
  224.     **
  225.     **    INPUT:    teHndl        TextEdit record to get height for.
  226.     **    RESULT:    short        Height of text in TextEdit record.
  227.     **
  228.     **    Returns the full TextEdit record text height.
  229.     **
  230.     **    __________
  231.     **
  232.     **    Also see:    CTEGetLineHeight, CTEGetLineNum. */
  233.  
  234. Boolean            CTEEditMenu(Boolean *activeItem, short editMenu, short undoID, short cutID);
  235.     /*
  236.     **    ¶ Handle the enabling and disabling of the Edit menu, based on the active TextEdit control.
  237.     **
  238.     **    INPUT:    editMenu    ID of Edit menu to adjust.
  239.     **            undoID        ID of Edit menu item for undo item.
  240.     **            cutID        ID of Edit menu item for cut item.
  241.     **    OUTPUT:    activeItem    Pointer to Boolean buffer.  True is returned if there is an active item.
  242.     **                        Pass in nil if you don’t care.
  243.     **    RESULT:    Boolean        True is returned if there is an active TextEdit record.
  244.     **
  245.     **    Enable or disable edit menu items based on the active TextEdit control.
  246.     **    You pass the menu ID of the undo item in undoID, and the menu ID of the
  247.     **    cut item in cutID.  If undoID or cutID is non-zero, then some action is
  248.     **    performed.  If you pass a non-zero value for cutID, then the other menu
  249.     **    items cut-copy-paste-clear are updated to reflect the status of the
  250.     **    active TextEdit control.
  251.     **
  252.     **    __________
  253.     **
  254.     **    Also see:    CTEClipboard, CTEConvertClipboard. */
  255.  
  256. Boolean            CTEEvent(WindowPtr window, EventRecord *event, short *action);
  257.     /*
  258.     **    ¶ Handle the event, either mouseDown or key event.
  259.     **
  260.     **    INPUT:    window        Window the event is for.
  261.     **            event        Pointer to the event record.
  262.     **    OUTPUT:    short        Pointer to a short buffer to hold the returned action.
  263.     **                        Pass in nil if you don’t care.
  264.     **    RESULT:    Boolean        True is returned if event is handled by a TextEdit control.
  265.     **
  266.     **    Handle the event if it applies to the active TextEdit control.  If some
  267.     **    action occured due to the event, return true.
  268.     **
  269.     **    if event not handled, false is returned and action is 0
  270.     **    if event handled, true is returned and action is:
  271.     **         -1: an inactive control was clicked on and it was made active.
  272.     **         0: an active control was clicked on and tracked.
  273.     **         1: the control took the keypress, but no change occured to the TERecord.
  274.     **         2: the control took the keypress and the TERecord changed.
  275.     **
  276.     **    __________
  277.     **
  278.     **    Also see:    CTEClick, CTEKey. */
  279.  
  280. TEHandle        CTEFindActive(WindowPtr window);
  281.     /*
  282.     **    ¶ See if there is an active TextEdit control for this window.
  283.     **
  284.     **    INPUT:    window        Window to check for an active TextEdit control (or nil for all).
  285.     **    RESULT:    TEHandle    The TEHandle of the active TextEdit control (or nil for none).
  286.     **
  287.     **    Returns the active TextEdit control, if any.  If nil is passed in, then
  288.     **    the return value represents whatever TextEdit control is active, independent
  289.     **    of what window it is in.  If a window is passed in, then it returns a
  290.     **    TextEdit control only if the active control is in the specified window.
  291.     **    If the active TextEdit control is in some other window, then nil is returned.
  292.     **
  293.     **    __________
  294.     **
  295.     **    Also see:    CTEActivate, CTEWindActivate. */
  296.  
  297.  
  298. ControlHandle    CTEFindCtl(WindowPtr window, EventRecord *event, TEHandle *teHndl,
  299.                            ControlHandle *ctlHit);
  300.     /*
  301.     **    ¶ See if a TextEdit control was clicked on directly.
  302.     **
  303.     **    INPUT:    window            Window to check for a clicked-on TextEdit control.
  304.     **            event            Pointer to the event record holding the mouseDown to check.
  305.     **    OUTPUT:    TEHandle        The TEHandle of the clicked-on TextEdit control (or nil for none).
  306.     **                            Pass in nil if you don’t care.
  307.     **            CtlHit            The control clicked-on (or nil for none).
  308.     **                            Pass in nil if you don’t care.
  309.     **    RESULT:    ControlHandle    The TextEdit control clicked-on (or nil for none).
  310.     **
  311.     **    This determines if a TextEdit control was clicked on directly.  The control found
  312.     **    and returned is the TextEdit control.  The control hit may be the same, or it may be
  313.     **    a related scrollbar. */
  314.  
  315. TEHandle        CTEFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
  316.     /*
  317.     **    ¶ Find the TextEdit record that is related to the indicated scrollbar.
  318.     **
  319.     **    INPUT:    scrollCtl        Window to check for a clicked-on TextEdit control.
  320.     **    OUTPUT:    retCtl            The TextEdit control related to the scrollBar (or nil for none).
  321.     **                            Pass in nil if you don’t care.
  322.     **    RESULT:    TEHandle        The TERecord clicked-on (or nil for none).
  323.     **
  324.     **    Find the TextEdit record that is related to the indicated scrollbar. */
  325.  
  326. Rect            CTEHide(TEHandle teHndl);
  327.     /*
  328.     **    ¶ Hide the designated TextEdit control and related scrollbars.
  329.     **
  330.     **    INPUT:    teHndl        TextEdit control to hide.
  331.     **    Rect:    Rect        Bounding box of area affected by hide.
  332.     **
  333.     **    Hide the designated TextEdit control and related scrollbars. */
  334.  
  335. void            CTEIdle(void);
  336.     /*
  337.     **    ¶ Blink the caret in the active TextEdit control.
  338.     **
  339.     **    Blink the caret in the active TextEdit control.  The active TextEdit
  340.     **    control may be read-only, in which case the caret does not blink. */
  341.  
  342. short            CTEKey(WindowPtr window, EventRecord *event);
  343.     /*
  344.     **    ¶ Does keypress apply to TextEdit control?  If so, handle it and return non-zero.
  345.     **
  346.     **    INPUT:    window        Window to check for active TextEdit control for key.
  347.     **            event        Pointer to event record holding keypress.
  348.     **    RESULT:    short        Action taken by TextEdit control due to keypress.
  349.     **
  350.     **    See if the keypress event applies to the TextEdit control, and if it does,
  351.     **    handle it and return non-zero.
  352.     **
  353.     **    if CTEKey returns 0, TextEdit control didn’t handle the event.
  354.     **    if CTEKey returns 1, TextEdit control did handle the event, but the TERecord didn’t change.
  355.     **    if CTEKey returns 2, TextEdit control did handle the event, and the TERecord changed. */
  356.  
  357. void            CTEMove(TEHandle teHndl, short newH, short newV);
  358.     /*
  359.     **    ¶ Move the designated TextEdit control and related scrollbars.
  360.     **
  361.     **    INPUT:    teHndl    TextEdit control to move.
  362.     **            newH    New horizontal location for TextEdit control.
  363.     **            newV    New vertical location for TextEdit control.
  364.     **
  365.     **    This function is used to move a TextEdit control.  Pass it the TextEdit
  366.     **    record to move, plus the new position.  It will move the TextEdit control,
  367.     **    along with any scrollbars the control may have.  All areas that need
  368.     **    updating are cleared and invalidated. */
  369.  
  370. OSErr            CTENew(short viewID, Boolean vis, WindowPtr window, TEHandle *teHndl, Rect *cRect,
  371.                        Rect *dRect, Rect *vRect, Rect *bRect, short maxTextLen, short mode);
  372.  
  373.     /*
  374.     **    ¶ Create a new TextEdit control.
  375.     **
  376.     **    INPUT:    viewID        Resource number of the stub CDEF.
  377.     **            vis            Create control initially visible.
  378.     **            window        Create control into this window.
  379.     **            cRect        Pointer to rect for TextEdit control view rect.
  380.     **            dRect        Pointer to rect for TextEdit destRect.
  381.     **            vRect        Pointer to rect for TextEdit viewRect.
  382.     **            bRect        Pointer to rect for TextEdit control border rect.
  383.     **            maxTextLen    Maximum length allowed for TextEdit record.
  384.     **            mode        Choose various TextEdit control options.
  385.     **    OUTPUT:    teHndl        Pointer to TEHandle to be created.
  386.     **                        Pass in nil if you don’t care.
  387.     **    RETURN:    OSErr        Reason for control creation failure.
  388.     **
  389.     **    To create a TextEdit control, you only need a single call.  For example:
  390.     **
  391.     **        mode = cteVScrollLessGrow;        TERecord read-write, with vertical scroll
  392.     **                                        that leaves space for grow box.
  393.     **
  394.     **        CTENew(rViewCtl,        Resource ID of view control for TextEdit control.
  395.     **               window,            Window to hold TERecord.
  396.     **               true,            Initially visible.
  397.     **               &teHndl,            Return handle for TERecord.
  398.     **               &ctlRect,        Rect for TextEdit view control.
  399.     **               &destRect,        destRect for TERecord.
  400.     **               &viewRect,        viewRect for TERecord.
  401.     **               &brdrRect,        Used to frame a border.
  402.     **               32000,            Max size for TERecord text.
  403.     **               mode);
  404.     **
  405.     **    The various choices for the TextEdit control are defined as follows:
  406.     **
  407.     **    #define cteReadOnly            0x0001
  408.     **    #define cteHScroll            0x0002
  409.     **    #define cteHScrollLessGrow    0x0006
  410.     **    #define cteVScroll            0x0008
  411.     **    #define cteVScrollLessGrow    0x0018
  412.     **    #define cteActive            0x0020
  413.     **    #define cteNoBorder            0x0040
  414.     **    #define cteShowActive        0x0080
  415.     **    #define cteTabSelectAll        0x0100
  416.     **    #define cteTwoStep            0x0200
  417.     **    #define cteScrollFullLines    0x0400
  418.     **    #define cteStyledTE            0x0800
  419.     **    #define cteCenterJustify    0x1000
  420.     **    #define cteRightJustify        0x2000
  421.     **    #define cteNoFastKeys        0x4000
  422.     **
  423.     **    cteReadOnly:        Don’t allow editing.  When selected, don’t blink a caret.
  424.     **                        Allow text selection and copy-to-clipboard.
  425.     **    cteHScroll:            Create and manage a horizontal scrollbar for the TextEdit control.
  426.     **    cteHScrollLessGrow:    Create and manage a horizontal scrollbar for the TextEdit control,
  427.     **                        but leave space for a growIcon on the right end of the scrollbar.
  428.     **    cteVScroll:            Create and manage a vertical scrollbar for the TextEdit control.
  429.     **    cteVScrollLessGrow:    Create and manage a vertical scrollbar for the TextEdit control,
  430.     **                        but leave space for a growIcon on the bottom end of the scrollbar.
  431.     **    cteActive:            Make this the initially active control for the window.
  432.     **    cteNoBorder:        By default, you get a border around the TextEdit control.  To turn this
  433.     **                        off, set this bit.
  434.     **    cteShowActive:        When the control is active, show that it is by drawing a selection
  435.     **                        border around the control.  This is the new 7.0 human-interface
  436.     **                        method of showing which control is active.  (This can be an important
  437.     **                        indicator because if you have readOnly TextEdit controls, they don’t
  438.     **                        have a blinking caret.  If they also don’t have any text selected,
  439.     **                        there will be no indication that it is the active control.
  440.     **    cteTabSelectAll:    When using IsCtlEvent (discussed under "! using CtlHandler.c"),
  441.     **                        tab changes the active TextEdit (or List) control.  When a TextEdit
  442.     **                        control is made active, sometimes it is desirable to initially select
  443.     **                        all of the text for the user.  Setting this bit accomplishes this.
  444.     **    cteTwoStep:            When using IsCtlEvent, you may want the initial click on a TextEdit
  445.     **                        control to just select the control, or you may wish the click to start
  446.     **                        tracking in addition to selecting the control.  The tracking is
  447.     **                        considered the second step, so by setting this bit, you will get
  448.     **                        tracking of the control on the initial click.
  449.     **    cteScrollFullLines:    This does as it sounds, but only if the TextEdit control isn’t styled.
  450.     **    cteStyledTE:        If you don’t need styles for this TextEdit control, leave this bit off.
  451.     **    cteCenterJustify:    As it sounds.
  452.     **    cteRightJustify:    As it sounds.
  453.     **    cteNoFastKeys:        The fast-keys feature allows the TextEdit control to check the OSEvent
  454.     **                        queue to see if there is another key event.  If there is, it will
  455.     **                        handle it before returning control to the application.  This local
  456.     **                        event processing allows a great speed increase in TextEdit performance,
  457.     **                        especially on slower Macs.  Some applications will want to inhibit
  458.     **                        this behavior.  Set this bit if you do.
  459.     **
  460.     **    Simply initialize ctlRect, destRect, viewRect, and brdrRect appropriately, and
  461.     **    then call CTENew (which stands for Control TENew).  If teHndl is returned
  462.     **    nil, then CTENew failed.  Otherwise, you now have a TextEdit control in the
  463.     **    window.  If it fails, it also returns an error stating why it failed
  464.     **    (memFullErr or resNotFound).
  465.     **
  466.     **    NOTE:    There is a TextEdit bug (no way!!) such that you may need to set the
  467.     **            viewRect right edge 2 bigger than the right edge of destRect.  If you
  468.     **            do not do this, then there will be some clipping on the right edge in
  469.     **            some cases.  Of course, you may want this.  You may want horizontal
  470.     **            scrolling, and therefore you would want the destRect substantially
  471.     **            larger than the viewRect.  If you don’t want horizontal scrolling,
  472.     **            then you probably don’t want any clipping horizontally, and therefore
  473.     **            you will need to set destRect.right 2 less than viewRect.right.
  474.     **
  475.     **
  476.     **    If the CTENew call succeeds, you then have a TextEdit control in your
  477.     **    window.  It will be automatically disposed of when you close the window.
  478.     **    If you don’t waht this to happen, then you can detach it from the
  479.     **    view control which owns it.  To do this, you would to the following:
  480.     **
  481.     **        viewCtl = CTEViewFromTE(theTextEditHndl);
  482.     **        if (viewCtl) SetCRefCon(viewCtl, nil);
  483.     **
  484.     **    The view control keeps a reference to the TERecord in the refCon.
  485.     **    If the refCon is cleared, then the view control does nothing.  So, all that
  486.     **    is needed to detach a TERecord from a view control is to set the
  487.     **    view control’s refCon nil.  Now if you close the window, you will still
  488.     **    have the TERecord.
  489.     **
  490.     **
  491.     **    To remove a TextEdit control completely from a window, you make one call:
  492.     **
  493.     **        CTEDispose(theTextEditHndl);
  494.     **
  495.     **    This disposes of the TERecord, the view control, and any scrollbar
  496.     **    controls that were created when the TextEdit control was created with
  497.     **    the call CTENew.
  498.     **
  499.     **
  500.     **    Events for TERecord are handled nearly automatically.  You can
  501.     **    make one of 3 calls:
  502.     **
  503.     **        CTEClick(window, eventPtr, &action);
  504.     **        CTEEvent(window, eventPtr, &action);
  505.     **        CTEKey(window, eventPtr);
  506.     **
  507.     **    In each case, if the event was handled, non-zero is returned.  CTEEvent simply
  508.     **    calls either CTEClick or CTEKey, whichever is appropriate.
  509.     **
  510.     **    Another call you will want to use is CTEEditMenu.  This is used to set the
  511.     **    state of cut/copy/paste/clear for TextEdit controls.  It checks the active
  512.     **    control to see if text is selected, if the control is read-only, etc.
  513.     **    Based on this information, it sets cut/copy/paste/clear either active
  514.     **    or inactive.  If any menu items are set active, it returns true.
  515.     **
  516.     **
  517.     **    One more high-level call is CTEUndo.  In response to an undo menu item
  518.     **    being selected by the user, just call CTEUndo, and the edits the user
  519.     **    has made will be undone.  (This includes undoing an undo.)
  520.     **
  521.     **
  522.     **    The last high-level call for managing the edit menu is CTEClipboard.  Call it
  523.     **    when you want to do a cut/copy/paste/clear for the active TextEdit control.
  524.     **    The value to pass is as follows:
  525.     **
  526.     **        2: cut
  527.     **        3: copy
  528.     **        4: paste
  529.     **        5: clear
  530.     **
  531.     **    These are the same values you would pass to a DA for these actions. */
  532.  
  533. void            CTENewUndo(ControlHandle viewCtl, Boolean alwaysNewUndo);
  534.     /*
  535.     **    ¶ Register a new undo for the next TextEdit control editing operation.
  536.     **
  537.     **    INPUT:    viewCtl            Control to set a new undo for.
  538.     **            alwaysNewUndo    True if undo should be forced.  (Not the case for normal typing.)
  539.     **
  540.     **    Save the data (if appropriate) so that user can undo. */
  541.  
  542. ControlHandle    CTENext(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  543.     /*
  544.     **    ¶ Interate to the next TextEdit control.
  545.     **
  546.     **    INPUT:    window            Window whose control list is iterated.
  547.     **            ctl                Last control.  Find next.  (Use nil to start at beginning of list.)
  548.     **            dir                1, walk control list forward.  -1, walk control list backward.
  549.     **            justActive        True is just active (visible, hilite != -1).
  550.     **    OUTPUT:    teHndl            Pointer to next TEHandle in list, based on criteria.
  551.     **                            Pass in nil if you don’t care.
  552.     **    RETURN:    ControlHandle    Next control in list, based on criteria.
  553.     **
  554.     **    Get the next TextEdit control in the window.  You pass it a control handle
  555.     **    for the view control, or nil to start at the beginning of the list.
  556.     **    It returns both a TextEdit handle and the view control handle for that
  557.     **    TextEdit record.  If none is found, nil is returned.  This allows you to
  558.     **    repeatedly call this function and walk through all the TextEdit controls
  559.     **    in a window. */
  560.  
  561. short            CTENumTextLines(TEHandle teHndl);
  562.     /*
  563.     **    ¶ Get correct number of line in the TextEdit handle.
  564.     **
  565.     **    INPUT:    teHndl        TextEdit handle to count lines on.
  566.     **    RETURN:    short        Number of lines in TextEdit handle.
  567.     **
  568.     **    Return the number of lines of text.  This is because there is a bug in
  569.     **    TextEdit where the number of lines returned is incorrect if the text
  570.     **    ends with a c/r.  This function adjusts for this bug. */
  571.  
  572. OSErr            CTEPrint(TEHandle teHndl, short *offset, Rect *rct);
  573.     /*
  574.     **    ¶ Get correct number of line in the TextEdit handle.
  575.     **
  576.     **    INPUT:    teHndl        TextEdit handle to print.
  577.     **    IN/OUT    offset        Pointer to short holding offset to continue printing from.
  578.     **            Rect        Pointer to rect that text is wrapped in, and wrapped text
  579.     **                        boundary is returned in.
  580.     **    RETURN:    OSErr        Some kind of error prevented completion (likely memFullErr).
  581.     **
  582.     **    Use this function to print the contents of a TextEdit record.  Pass it a
  583.     **    TextEdit handle, a pointer to a text offset, and a pointer to a rect to
  584.     **    print the text in.  The offset should be initialized to what character
  585.     **    in the TextEdit record you wish to start printing at (most likely 0).
  586.     **    The print function prints as much text as will fit in the rect, and
  587.     **    then updates the offset to tell you what is the first character that didn’t
  588.     **    print.  You can then call the print function again with another rect with
  589.     **    this new offset, and it will print the text starting at the new offset.
  590.     **    This method is very useful when a single TextEdit record is longer than a
  591.     **    single page, and you wish the text to break at the end of the page.
  592.     **    The bottom of rect is also updated, along with the offset.  The bottom edge
  593.     **    of the rect is changed to reflect the actual bottom of the text printed.
  594.     **    This is useful because the rect passed in didn’t necessarily hold an
  595.     **    integer number of lines of text.  The bottom of the rect is adjusted so
  596.     **    it exactly holds complete lines of text.
  597.     **    It is also possible that the rect could hold substantially more lines of
  598.     **    text than there are remaining.  Again, in this situation, the bottom of
  599.     **    rect is adjusted so that the rect tightly bounds the text printed.
  600.     **    The remaining piece of information passed back is an indicator that the
  601.     **    text through the end of the TextEdit record was printed.  When the end
  602.     **    of the text is reached, the offset for the next text to be printed is
  603.     **    returned as -1.  This indicates that processing of the TextEdit record
  604.     **    is complete. */
  605.  
  606. Boolean            CTEReadOnly(TEHandle teHndl);
  607.     /*
  608.     **    ¶ Return if the TextEdit control is read-write (true) or read-only (false).
  609.     **
  610.     **    INPUT:    teHndl        TextEdit handle in question.
  611.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  612.     **
  613.     **    Return if the TextEdit control is read-write (true) or read-only (false). */
  614.  
  615. ControlHandle    CTEScrollFromTE(TEHandle teHndl, Boolean vertScroll);
  616.     /*
  617.     **    ¶ Return control handle of scrollbar related to the TextEdit record.
  618.     **
  619.     **    INPUT:    teHndl        TextEdit handle in question.
  620.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  621.     **
  622.     **    Return the control handle for the TextEdit control’s scrollbar, either
  623.     **    vertical or horizontal.  If the scrollbar doesn’t, nil is returned. */
  624.  
  625. ControlHandle    CTEScrollFromView(ControlHandle viewCtl, Boolean vertScroll);
  626.     /*
  627.     **    ¶ Return control handle of scrollbar related to the TextEdit control.
  628.     **
  629.     **    INPUT:    viewCtl        TextEdit control in question.
  630.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  631.     **
  632.     **    Return the control handle for the scrollbar related to the view control,
  633.     **    either horizontal or vertical.  If the scrollbar doesn’t exist, return nil. */
  634.  
  635. void            CTESetKeyFilter(TEHandle teHndl, CTEKeyFilterProcPtr proc);
  636.     /*
  637.     **    ¶ Set TextEdit handle to be filtered.
  638.     **
  639.     **    INPUT:    teHndl        TextEdit handle to be filtered.
  640.     **            proc        Filter procedure for TextEdit handle.
  641.     **
  642.     **    A TextEdit control can have an optional key filter, which is called whenever
  643.     **    CTEKey is called.  If you pass in nil, then the filtering is turned off.
  644.     **    This allows individual TextEdit controls to handle their own filtering.
  645.     **    The filter procedure is of the form:
  646.     **        Boolean (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, Boolean *handled);
  647.     **    If true is returned, then CTEKey is aborted, and the value in "handled" is
  648.     **    returned.  By having a separate abort value and return value, you can determine
  649.     **    if processing of the event should be continued or not, independent of whether
  650.     **    or not you aborted CTEKey. */
  651.  
  652. void            CTESetFastKeys(TEHandle teHndl, CTEFastKeysProcPtr proc);
  653.     /*
  654.     **    ¶ Set TextEdit handle to accept keys "fast", i.e., in a local loop.
  655.     **
  656.     **    INPUT:    teHndl        TextEdit handle to be filtered.
  657.     **            proc        Fast-keys procedure.
  658.     **
  659.     **    Set your own fast-keys procedure.  The fast-keys procedure returns whether or not
  660.     **    the particular keypress can be handled without returning to the application.
  661.     **    If the key can be handled as a fast key, then the proc should return true. */
  662.  
  663. void            CTESetSelect(short start, short end, TEHandle teHndl);
  664.     /*
  665.     **    ¶ Set a range of text.  Use this instead of TESetSelect.
  666.     **
  667.     **    INPUT:    start        Offset of first char to be included in the selection range.
  668.     **            stop        Offset past last character to be included in the selection range.
  669.     **            teHndl        TextEdit handle to receive selection range.
  670.     **
  671.     **    Select a range of text.  TESetSelect can’t be used alone because it doesn’t
  672.     **    update the scrollbars.  This function calls TESetSelect, and then fixes up
  673.     **    the scrollbars. */
  674.  
  675. void            CTEShow(TEHandle teHndl);
  676.     /*
  677.     **    ¶ Unhide a hidden TextEdit control.
  678.     **
  679.     **    INPUT:    teHndl        TextEdit handle to unhide.
  680.     **
  681.     **    Show the designated TextEdit control and related scrollbars. */
  682.  
  683. void            CTESize(TEHandle teHndl, short newH, short newV, Boolean newDest);
  684.     /*
  685.     **    ¶ Change the size of a TextEdit control and related scrollbars.
  686.     **
  687.     **    INPUT:    teHndl        TextEdit handle to resize.
  688.     **            newH        New horizontal size.
  689.     **            newV        New vertical size.
  690.     **            newDest        Resize the destRect, along with other changes.
  691.     **
  692.     **    This function is used to resize a TextEdit control.  Pass it the TextEdit
  693.     **    record to resize, plus the new horizontal and vertical size.  It will
  694.     **    resize the TextEdit control, realign the text, if necessary, plus it will
  695.     **    resize and adjust any scrollbars the TextEdit control may have.  All areas
  696.     **    that need updating are cleared and invalidated. */
  697.  
  698. Handle            CTESwapText(TEHandle teHndl, Handle newText, StScrpHandle styl, Boolean update);
  699.     /*
  700.     **    ¶ Change the size of a TextEdit control and related scrollbars.
  701.     **
  702.     **    INPUT:    teHndl        TextEdit handle to accept text.
  703.     **            newText        Handle of new text for TextEdit control.
  704.     **            styl        Optional style record (nil if none).
  705.     **            update        True if new text should be drawn after being accepted.
  706.     **
  707.     **    Swap the TextEdit text handle with the text handle passed in.  If a non-nil styl
  708.     **    value is passed in, apply the style scrap to the new text.  A typical usage
  709.     **    might look like:
  710.     **
  711.     **        DisposeHandle(CTESwapText(teHndl, textHndl, stylHndl, false));
  712.     **
  713.     **    CTESwapText returns the old handle, which is then disposed of, since it is
  714.     **    typically no longer needed. */
  715.  
  716.  
  717. WindowPtr        CTETargetInfo(TEHandle *teHndl, Rect *teView);
  718.     /*
  719.     **    ¶ Get information about the target TextEdit control.
  720.     **
  721.     **    OUTPUT:    teHndl        Active TextEdit handle (nil if none).
  722.     **                        Pass in nil if you don’t care.
  723.     **            teView        Bounding viewRct of activeTextEdit handle.
  724.     **                        Pass in nil if you don’t care.
  725.     **    RESULT:    WindowPtr    Window containing active TextEdit control.
  726.     **
  727.     **    Return information for the currently active TextEdit control.  The currently
  728.     **    active TextEdit control is stored in gActiveTEHndl, and can be accessed
  729.     **    directly.  If gActiveTEHndl is nil, then there is no currently active one.
  730.     **    The information that we return is the viewRect and window of the active
  731.     **    TextEdit control.  This is information that could be gotten directly, but
  732.     **    this call makes it a little more convenient. */
  733.  
  734. ControlHandle    CTEUndo(void);
  735.     /*
  736.     **    ¶ Perform an undo function for the TextEdit control.
  737.     **
  738.     **    Perform an undo function for the TextEdit control.
  739.     **    If a TextEdit control content changes due to this operation, the control
  740.     **    handle is returned. */
  741.  
  742. void            CTEUpdate(TEHandle teHndl, ControlHandle ctl, Boolean justShowActive);
  743.     /*
  744.     **    ¶ Draw the TextEdit control and frame.
  745.     **
  746.     **    INPUT:    teHndl                TextEdit handle to draw.
  747.     **            ctl                    TextEdit control to draw.
  748.     **            justShowActive        Just draw the active indicator, if any.
  749.     **
  750.     **    Draw the TextEdit control and frame, or possibly just the frame. */
  751.  
  752. ControlHandle    CTEViewFromTE(TEHandle teHndl);
  753.     /*
  754.     **    ¶ Get the control handle, give the TextEdit record.
  755.     **
  756.     **    INPUT:    teHndl                TextEdit handle to convert to control.
  757.     **
  758.     **    Return the control handle for the view control that owns the TextEdit
  759.     **    record.  Use this to find the view to do customizations such as changing
  760.     **    the update procedure for this TextEdit control. */
  761.  
  762. TEHandle        CTEWindActivate(WindowPtr window, Boolean displayIt);
  763.     /*
  764.     **    ¶ Activate the TextEdit control for the activating window.
  765.     **
  766.     **    INPUT:    window            Window that was activated.
  767.     **            displayIt        Display the activation differences.
  768.     **    RETURN:    TEHandle        The activated TextEdit handle (or nil for none).
  769.     **
  770.     **    Call this when a window with TextEdit controls is being activated.  This
  771.     **    will make the TextEdit control that was last active in this window the
  772.     **    active TextEdit control again. */
  773.  
  774. void            CTEAdjustTEBottom(TEHandle teHndl);
  775.     /*
  776.     **    ¶ Adjust the bottom of the TextEdit record to remove extra white space.
  777.     **
  778.     **    INPUT:    teHndl            TextEdit record to adjust.
  779.     **
  780.     **    This function is called after an edit to make sure that there is no extra
  781.     **    white space at the bottom of the viewRect.  If there are blank lines at
  782.     **    the bottom of the viewRect, and there is text scrolled off the top of the
  783.     **    viewRect, then the TextEdit control is scrolled to fill this space, or as
  784.     **    much of it as possible. */
  785.  
  786. void            CTEAdjustScrollValues(TEHandle teHndl);
  787.     /*
  788.     **    ¶ Adjust the scrollbar values to the TextEdit length and scroll position.
  789.     **
  790.     **    INPUT:    teHndl        TextEdit record whose scrollbars are to be adjusted.
  791.     **
  792.     **    Bring the scrollbar values up to date with the current document position
  793.     **    and length. */
  794.  
  795. StScrpHandle    CTEGetFullStylScrap(TEHandle teHndl);
  796.     /*
  797.     **    ¶ Get the style scrap for the entire TextEdit control.
  798.     **
  799.     **    INPUT:    teHndl        TextEdit record to get scrap for.
  800.     **
  801.     **    This function gets the style scrap for the entire TextEdit control.  It doesn’t
  802.     **    matter what the current selection range is.  The TextEdit control is left unaffected. */
  803.  
  804. void            CTESetStylScrap(short begRng, short endRng, StScrpHandle styles, TEHandle teHndl);
  805.     /*
  806.     **    ¶ Apply the style scrap to the TextEdit record.
  807.     **
  808.     **    INPUT:    begRng        Beginning of range (inclusive) to apply style to.
  809.     **            endRng        End of range (exclusive) to apply style to.
  810.     **            styles        Scrap syyles to apply.
  811.     **            teHndl        TextEdit record to apply styles to.
  812.     **
  813.     **    This function applies the style scrap to the TextEdit record.  This function works better
  814.     **    than the toolbox function TESetStylScrap. */
  815.  
  816. short            CTEGetLineNum(TEHandle te, short offset);
  817.     /*
  818.     **    ¶ Return the line number associated with the offset passed in.
  819.     **
  820.     **    INPUT:    te            TextEdit handle to get the line number for.
  821.     **            offset        Offset to find the line number for.
  822.     **
  823.     **    This function returns the line number associated with the offset passed in. */
  824.  
  825. short            CTEGetLineHeight(TEHandle te, short lineNum, short *ascent);
  826.     /*
  827.     **    ¶ Return the line height of the requested line number.
  828.     **
  829.     **    INPUT:    te            TextEdit handle to get the line number for.
  830.     **            lineNum        Line number to get height for.
  831.     **    OUTPUT:    ascent        Ascent of line lineNum.
  832.     **                        Pass in nil if you don’t care.
  833.     **    RESULT:    short        Line height of line lineNum.
  834.     **
  835.     **    This function returns the line height of the requested line number. */
  836.  
  837. void            CTEGetPStr(ControlHandle ctl, StringPtr pstr);
  838.     /*
  839.     **    ¶ Return the TextEdit control text as a pascal string.
  840.     **
  841.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  842.     **    OUTPUT:    pstr        Pascal string pointer to receive text.
  843.     **
  844.     **    This function returns the TextEdit control text as a pascal string.  The maximum text
  845.     **    returned is 255 chars. */
  846.  
  847. void            CTEPutPStr(ControlHandle ctl, StringPtr pstr);
  848.     /*
  849.     **    ¶ Set the TextEdit control text to a pascal string.
  850.     **
  851.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  852.     **            pstr        Pascal string pointer that holds new TextEdit control text.
  853.     **
  854.     **    This function sets the TextEdit control text to the pascal string. */
  855.  
  856. void            CTESetPStr(ControlHandle ctl, StringPtr pstr);
  857.     /*
  858.     **    ¶ Set the TextEdit control text to a pascal string.
  859.     **
  860.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  861.     **            pstr        Pascal string pointer that holds new TextEdit control text.
  862.     **
  863.     **    This function sets the TextEdit control text to the pascal string. */
  864.  
  865. Boolean            CTEUseTSMTE(void);
  866.     /*
  867.     **    ¶ Set the TextEdit control to use TSMTE.
  868.     **
  869.     **    OUTPUT:    Boolean        Returns true if can use TSMTE.
  870.     **
  871.     **    Call this function if you want the TextEdit control to use TSMTE.  You still need to
  872.     **    register and unregister your application with the TextServices Manager.  That isn’t
  873.     **    handled for you.  AppWannabe’s Start.c file shows how this is done:
  874.     **
  875.     **    if(CTEUseTSMTE())
  876.     **        InitTSMAwareApplication();
  877.     **
  878.     **    ... do app things here ...
  879.     **
  880.     **    if(CTEUseTSMTE())
  881.     **        CloseTSMAwareApplication();
  882.     **
  883.     **    ExitToShell();
  884.     */
  885.  
  886. Boolean            TSMTEAvailable(void);
  887.     /*
  888.     **    ¶ Check if TextServices init TSMTE is available.
  889.     **
  890.     **    OUTPUT:    Boolean        Returns true if TSMTE is available.
  891.     **
  892.     **    This function says if the TextServices init TSMTE is available for inline-input for
  893.     **    TextEdit.  Note that you should do the following at startup:
  894.     **
  895.     **            if(TSMTEAvailable())
  896.     **            InitTSMAwareApplication();
  897.     **
  898.     **    And at application shutdown, you should do the following:
  899.     **
  900.     **            if(TSMTEAvailable())
  901.     **            CloseTSMAwareApplication();
  902.     */
  903.  
  904. Boolean            IsTECtl(ControlHandle ctl);
  905.     /*
  906.     **    ¶ Check if the control is a TextEdit control.
  907.     **
  908.     **    INPUT:    ctl            Handle of control to test to see if it is a TextEdit control.
  909.     **    RESULT:    Boolean        True if control is a TextEdit control.
  910.     **
  911.     **    Check to see if the control is a TextEdit control. */
  912.  
  913.  
  914.  
  915. #ifdef __cplusplus
  916. }
  917. #endif
  918.  
  919.  
  920.  
  921. typedef void            (*CTEActivateProcPtr)(Boolean active, TEHandle teHndl);
  922. typedef Boolean            (*CTEClickProcPtr)(WindowPtr window, EventRecord *event, short *action);
  923. typedef ControlHandle    (*CTECtlHitProcPtr)(void);
  924. typedef TEHandle        (*CTEFindActiveProcPtr)(WindowPtr window);
  925. typedef short            (*CTEKeyProcPtr)(WindowPtr window, EventRecord *event);
  926. typedef ControlHandle    (*CTENextProcPtr)(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  927. typedef void            (*CTESetSelectProcPtr)(short start, short end, TEHandle teHndl);
  928. typedef ControlHandle    (*CTEViewFromTEProcPtr)(TEHandle teHndl);
  929. typedef TEHandle        (*CTEWindActivateProcPtr)(WindowPtr window, Boolean displayIt);
  930.  
  931. #define rTECtl                4000
  932.  
  933. #define cteReadOnly            0x0001
  934. #define cteHScroll            0x0002
  935. #define cteHScrollLessGrow    0x0006
  936. #define cteVScroll            0x0008
  937. #define cteVScrollLessGrow    0x0018
  938. #define cteActive            0x0020
  939. #define cteNoBorder            0x0040
  940. #define cteShowActive        0x0080
  941. #define cteTabSelectAll        0x0100
  942. #define cteTwoStep            0x0200
  943. #define cteScrollFullLines    0x0400
  944. #define cteStyledTE            0x0800
  945. #define cteCenterJustify    0x1000
  946. #define cteRightJustify        0x2000
  947. #define cteNoFastKeys        0x4000
  948. #define cteTSMTE            0x8000
  949.  
  950. #endif
  951.